package com.wjs.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier barrier = new CyclicBarrier(7, () -> {
            System.out.println("神龙出现！！！");
        });
        for (int i = 1; i <= 7; i++) {
            new Thread(()->{
                try {
                    System.out.println(Thread.currentThread().getName()+"星球被收集");
                    barrier.await();
                    System.out.println(Thread.currentThread().getName()+Thread.currentThread().getState());
                } catch (Exception e) {
                }
            },String.valueOf(i)).start();
        }
    }
}
